package com.gd.iot.energy.controller.superadmin;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.superadmin.dto.LogVOWithBLOBs;
import com.gd.iot.energy.pojo.superadmin.vo.LogPageVO;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.service.superadmin.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 超级管理-用户管理-系统日志
 *
 * @author kris
 * @date Created at 2020/8/3 10:50
 */
@Api(value = "超级管理-用户管理-系统日志",tags = "超级管理-用户管理-系统日志")
@RestController
@RequestMapping("/admin/log")
public class LogController {

    @Autowired
    private LogService logService;

    @ApiOperation("日志分页列表")
    @SystemLogRecordMonitor("日志分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "operator", value = "操作者", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "operation", value = "操作", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getPageList")
    public ResponseEntity<PageVO<LogPageVO>> getPageList(
            @RequestParam(value = "operator",required = false)String operator,
            @RequestParam(value = "operation",required = false)String operation,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "desc") String orderType
    ) {

        PageVO<LogPageVO> pageVO = logService.getPageLogVOs(operator,operation,pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("获取日志")
    @SystemLogRecordMonitor("获取日志")
    @PostMapping("/get")
    public ResponseEntity<LogVOWithBLOBs> get(Integer id){
        LogVOWithBLOBs logVOWithBLOBs = logService.getLog(id);
        return new ResponseEntity<>(logVOWithBLOBs);
    }

    @ApiOperation("删除日志")
    @SystemLogRecordMonitor("删除日志")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody List<Integer> ids){
        boolean res = logService.delete(ids);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("清空日志")
    @SystemLogRecordMonitor("清空日志")
    @PostMapping("/clearAll")
    public ResponseEntity<Boolean> clearAll(){
        boolean res = logService.clearAll();
        return new ResponseEntity<>(res);
    }

}
